# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import Union
from pydantic import BaseModel, Field
from fastapi import Query


class DocsFilesSearchIn(BaseModel):
    """ 文件搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    name: Union[str, None] = Query(default=None, description="文件名称")
    user: Union[str, None] = Query(default=None, description="用户信息")


class DocsFilesDatesetIn(BaseModel):
    """ 文件数据参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    file_id: int = Query(..., gt=0, description="文件ID")


class DocsFilesIdIn(BaseModel):
    """ 文件ID参数 """
    id: int = Field(..., gt=0, description="文件ID")
    reason: str = Field(default="", description="原因描述")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "reason": "原因说明"
            }
        }


"""--------------- Separator ---------------"""


class DocsFilesListVo(BaseModel):
    """ 文件列表Vo """
    id: int = Field(description="文件ID")
    code: str = Field(description="文件编号")
    name: str = Field(description="文件名称")
    size: int = Field(description="文件大小")
    ext: str = Field(description="文件扩展")
    error: str = Field(description="失败原因")
    status: int = Field(description="训练状态: [0=待训练,1=训练中,2=训练成功,3=训练失败]")
    ip: str = Field(description="来源IP")
    raw_path: str = Field(description="原始文件")
    pdf_path: str = Field(description="PDF文件")
    vector_alias: str = Field(description="解析模型")
    create_time: str = Field(description="创建时间")
    user: dict = Field(description="用户信息")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "code": "5526cb6f946d378a2c15cf45b16a0761",
                "name": "招标合同.pdf",
                "size": 301594,
                "ext": "pdf",
                "error": "",
                "status": 2,
                "ip": "127.0.0.1",
                "raw_path": "https://raw/3237c9.pdf",
                "pdf_path": "https://pdf/3237c9.pdf",
                "vector_alias": "智谱清言",
                "create_time": "2025-05-08 11:00:56",
                "user": {
                    "sn": "52778960",
                    "nickname": "TW",
                    "mobile": "13800138000",
                    "avatar": "https://xx.com/images/avatar.png"
                }
            }
        }


class DocsDatasetVo(BaseModel):
    """ 文件数据Vo """
    uuid: str = Field(description="UUID")
    page_nv: str = Field(description="范围页码")
    page_no: int = Field(description="当前页码")
    question: str = Field(description="分片内容")
    dimension: int = Field(description="向量维度")
    chunk_index: int = Field(description="分片下标")
    status: int = Field(description="索引状态: [0=待索引,1=排队中,2=索引中,3=已就绪,4=索引失败]")
    create_time: str = Field(description="创建时间")

    class Config:
        json_schema_extra = {
            "example": {
                "uuid": "58a6f2a4-2cd9-4978-b7e3-4c9e4bf0de72",
                "page_nv": "1,2",
                "page_no": 1,
                "question": "广东省建筑科学研究院....",
                "dimension": 2048,
                "chunk_index": 1,
                "status": 2,
                "create_time": "2025-05-08 11:00:56"
            }
        }
